#include "util.hpp"

int main()
{
    char buffer[1024];
    while (1)
    {
        setNonBlock(0);
        std::cout << ">>>> ";
        fflush(stdout);
        ssize_t s = read(0, buffer, sizeof(buffer) - 1);
        if (s > 0)
        {
            buffer[s] = 0;
            std::cout << "echo# " << buffer << std::endl;
        }
        else if (s == 0)
        {
            std::cout << "read end" << std::endl;
            break;
        }
        else
        {
            if (errno == EAGAIN)
            {
                std::cout << "没有错，只是没有数据" << std::endl;
            }
            else if (errno == EINTR)
            {
                std::cout << "系统调用被中断" << std::endl;
                continue;
            }
            else
            {
                std::cout << "出错" << std::endl;
                break;
            }
        }
    }
    return 0;
}